﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Ext.Net;

public partial class SYS_POPEDOM_Sys_Params : BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            
        }
    }

    protected void MyData_Refresh(object sender, StoreRefreshDataEventArgs e)
    {
        BindGridData(e);
    }

    private void BindGridData(StoreRefreshDataEventArgs e)
    {
        int recordcount = CommonLib.BLL.BS_DATASET_SQL.SqlGetTable("select * from SYS_PARAMETER" + GetQryString()).Rows.Count;
        BindGridPSData(e, "", PagingToolBar1, Store1, recordcount);
    }

    protected void OnBtnSearchClick(object sender, DirectEventArgs e)
    {
        this.GridPanel1.Reload();
    }

    private string GetQryString()
    {
        string result = " where 1=1 ";

        if (!string.IsNullOrEmpty(exttxt_PARAMETER_ID.Text.Trim()))
            result += " and  PARAMETER_ID like '%" + exttxt_PARAMETER_ID.Text.Trim() + "%'";
        if (!string.IsNullOrEmpty(exttxt_REMARK.Text.Trim()))
            result += " and  REMARK like '%" + exttxt_REMARK.Text.Trim() + "%'";
        return result;
    }

    public override DataTable GetPSData(int PageSize, int CurPage, string OrderStr)
    {
        DataTable dt = CommonLib.BLL.BS_DATASET_SQL.SqlGetTable("select * from SYS_PARAMETER" + GetQryString());
        return dt;
    }

    [DirectMethod]
    public void OnAfterEdit(string PARAMETER_ID, string PARAMETER_NAME, string PARAMETER_STR, string REMARK)
    {
        try
        {
            DataTable dt = CommonLib.BLL.SYS_PARAMETER.GetList("PARAMETER_ID='" + PARAMETER_ID + "'").Tables[0];
            var model = CommonLib.BLL.SYS_PARAMETER.GetModel(PARAMETER_ID);
            if (model == null)
            {
                Store1.RejectChanges();
                return;
            }

            model.PARAMETER_ID = PARAMETER_ID;
            model.PARAMETER_NAME = PARAMETER_NAME;
            model.PARAMETER_STR = PARAMETER_STR;
            model.REMARK = REMARK;
            CommonLib.BLL.SYS_PARAMETER.Update(model);
            Store1.CommitChanges();
        }
        catch (Exception ex)
        {
            Store1.RejectChanges();
            X.Msg.Alert("系统错误", "修改失败|" + ex.Message).Show();
        }
    }

}
